package utils

import (
	"bytes"
	"encoding/binary"
	"fmt"
	"github.com/satori/go.uuid"
	"runtime"
)

func StrIsEmpty(str string) bool  {
	return str==""||&str==nil
}

func GenUUID() string {
	u1, err:=uuid.NewV4()
	if err!=nil{
		fmt.Println(err.Error())
		return ""
	}
	return u1.String()
}

//整形转换成字节
func IntToBytes(n int) []byte {
	x := int32(n)

	bytesBuffer := bytes.NewBuffer([]byte{})
	binary.Write(bytesBuffer, binary.BigEndian, x)
	return bytesBuffer.Bytes()
}

//字节转换成整形
func BytesToInt(b []byte) int {
	bytesBuffer := bytes.NewBuffer(b)
	var x int32
	binary.Read(bytesBuffer, binary.BigEndian, &x)
	runtime.GC()
	return int(x)
}

func SafeSend(ch chan interface{}, value interface{}) (closed bool) {
	defer func() {
		if recover() != nil {
			closed = true
		}
	}()
	ch <- value
	return false
}


